import time

import akshare as ak
import pandas as pd

# 升级akshare
# pip install akshare --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple

# A股股票指数数据 - 实时行情数据 - 东财
# "上证系列指数", "深证系列指数", "指数成份", "中证系列指数"
# df1 = ak.stock_zh_index_spot_em(symbol="上证系列指数")
# df2 = ak.stock_zh_index_spot_em(symbol="深证系列指数")
# df3 = ak.stock_zh_index_spot_em(symbol="指数成份")
# df4 = ak.stock_zh_index_spot_em(symbol="中证系列指数")
#
# df = pd.concat([df1, df2, df3, df4])
# df = df.drop_duplicates(subset=["代码", "名称"])
# print(df)
# date = time.strftime("%Y%m%d", time.localtime())
# df.to_excel(f"A股指数-东财-{date}.xlsx")

# A股股票指数数据 - 实时行情数据-新浪
# df = ak.stock_zh_index_spot_sina()
# df.to_csv("A股指数-新浪.csv")
# print(df)

# A股股票指数数据 - 历史行情数据-通用
symbol = "000991"
df = ak.index_zh_a_hist(symbol=symbol)
print(df)
df.to_csv(f"A股指数-{symbol}-历史行情数据.csv", index=False)

